package com.shangcheng.server.controller;

import com.shangcheng.model.domain.PmsSkuStock;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.PmsSkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sku")
public class PmsSkuStockController {
    @Autowired
    private PmsSkuStockService skuStockService;

    /**
     * 批量更新sku库存信息
     *
     * @param pid
     * @param skuStockList
     * @return
     */
    @PostMapping("/update/{pid}")
    public Result updateByPid(@PathVariable("pid") Integer pid, @RequestBody List<PmsSkuStock> skuStockList) {
        skuStockService.updateByPid(pid, skuStockList);
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    /**
     * 根据商品ID及sku编码模糊搜索sku库存
     *
     * @param pid
     * @param keyword
     * @return
     */
    @GetMapping("/{pid}")
    public Result findByPidOrCode(@PathVariable("pid") Integer pid, String keyword) {
        List<PmsSkuStock> list = skuStockService.findByPidOrCode(pid, keyword);
        return new Result(200, list, "操作成功");
    }
}
